import * as crypto from 'crypto'
import { APP_SECRET } from './../constants/index'

export const md5 = (content: string): string => {
  return crypto.createHash('md5').update(content).digest('hex')
}

export const sign = (params: object) => {
  let result = `${APP_SECRET}`
  const keys = Object.keys(params).sort()
  keys.forEach(key => {
    result += `${key}${params[key]}`
  })

  return md5(result).toUpperCase()
}
